<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册与登录</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary-color: #3498db;
            --secondary-color: #2ecc71;
            --error-color: #e74c3c;
            --warning-color: #f39c12;
            --dark-color: #2c3e50;
            --light-color: #ecf0f1;
            --text-color: #333;
            --border-color: #ddd;
            --shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #3498db, #8e44ad);
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            width: 100%;
            max-width: 900px;
            display: flex;
            flex-direction: column;
            gap: 30px;
        }
        
        .header {
            text-align: center;
            margin-bottom: 20px;
            color: white;
        }
        
        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
        }
        
        .header p {
            font-size: 1.1rem;
            opacity: 0.9;
        }
        
        .content {
            display: flex;
            gap: 30px;
            flex-wrap: wrap;
        }
        
        .card {
            flex: 1;
            min-width: 300px;
            background: white;
            border-radius: 15px;
            box-shadow: var(--shadow);
            padding: 30px;
            transition: transform 0.3s ease;
        }
        
        .card:hover {
            transform: translateY(-5px);
        }
        
        .card h2 {
            color: var(--primary-color);
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 2px solid var(--light-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .card h2 i {
            font-size: 1.5rem;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--text-color);
        }
        
        input {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid var(--border-color);
            border-radius: 5px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        
        input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }
        
        button {
            width: 100%;
            padding: 12px;
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 8px;
        }
        
        button:hover {
            background-color: #2980b9;
        }
        
        .btn-secondary {
            background-color: var(--secondary-color);
        }
        
        .btn-secondary:hover {
            background-color: #27ae60;
        }
        
        .btn-outline {
            background-color: transparent;
            border: 1px solid var(--primary-color);
            color: var(--primary-color);
        }
        
        .btn-outline:hover {
            background-color: rgba(52, 152, 219, 0.1);
        }
        
        .message {
            margin-top: 15px;
            padding: 10px;
            border-radius: 5px;
            text-align: center;
            display: none;
        }
        
        .success {
            background-color: rgba(46, 204, 113, 0.1);
            color: var(--secondary-color);
            border: 1px solid var(--secondary-color);
        }
        
        .error {
            background-color: rgba(231, 76, 60, 0.1);
            color: var(--error-color);
            border: 1px solid var(--error-color);
        }
        
        .warning {
            background-color: rgba(243, 156, 18, 0.1);
            color: var(--warning-color);
            border: 1px solid var(--warning-color);
        }
        
        .api-info {
            background-color: white;
            border-radius: 10px;
            box-shadow: var(--shadow);
            padding: 20px;
            margin-top: 20px;
        }
        
        .api-info h3 {
            color: var(--primary-color);
            margin-bottom: 15px;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .status-codes {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 10px;
            margin-top: 15px;
        }
        
        .status-code {
            padding: 8px 12px;
            border-radius: 5px;
            font-size: 14px;
            background-color: var(--light-color);
        }
        
        .status-code .code {
            font-weight: bold;
            margin-right: 5px;
        }
        
        .user-info {
            background-color: white;
            border-radius: 10px;
            box-shadow: var(--shadow);
            padding: 20px;
            margin-top: 20px;
            display: none;
        }
        
        .user-info h3 {
            color: var(--primary-color);
            margin-bottom: 15px;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .user-details {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 15px;
        }
        
        .user-detail {
            padding: 10px;
            border-radius: 5px;
            background-color: var(--light-color);
        }
        
        .user-detail .label {
            font-weight: bold;
            color: var(--dark-color);
            margin-bottom: 5px;
        }
        
        .toggle-container {
            display: flex;
            justify-content: center;
            margin-top: 20px;
        }
        
        @media (max-width: 768px) {
            .content {
                flex-direction: column;
            }
            
            .card {
                min-width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>用户注册与登录</h1>
            <p>请使用以下表单进行用户登录，如需注册请点击注册按钮</p>
        </div>
        
        <div class="content">
            <div class="card">
                <h2><i class="fas fa-sign-in-alt"></i>用户登录</h2>
                <form id="loginForm">
                    <div class="form-group">
                        <label for="loginUsername">用户名</label>
                        <input type="text" id="loginUsername" name="username" required>
                    </div>
                    <div class="form-group">
                        <label for="loginPassword">密码</label>
                        <input type="password" id="loginPassword" name="password" required>
                    </div>
                    <button type="submit"><i class="fas fa-sign-in-alt"></i>登录</button>
                    <div id="loginMessage" class="message"></div>
                </form>
                
                <div class="toggle-container">
                    <button id="showRegisterBtn" class="btn-outline"><i class="fas fa-user-plus"></i>前往注册</button>
                </div>
            </div>
            
            <div class="card" id="registerCard" style="display: none;">
                <h2><i class="fas fa-user-plus"></i>用户注册</h2>
                <form id="registerForm">
                    <div class="form-group">
                        <label for="regUsername">用户名</label>
                        <input type="text" id="regUsername" name="username" required>
                    </div>
                    <div class="form-group">
                        <label for="regPassword">密码</label>
                        <input type="password" id="regPassword" name="password" required>
                    </div>
                    <div class="form-group">
                        <label for="regEmail">邮箱</label>
                        <input type="email" id="regEmail" name="email" required>
                    </div>
                    <div class="form-group">
                        <label for="regPhone">手机号</label>
                        <input type="tel" id="regPhone" name="phone" required>
                    </div>
                    <button type="submit" class="btn-secondary"><i class="fas fa-user-plus"></i>注册</button>
                    <div id="registerMessage" class="message"></div>
                </form>
                
                <div class="toggle-container">
                    <button id="showLoginBtn" class="btn-outline"><i class="fas fa-sign-in-alt"></i>返回登录</button>
                </div>
            </div>
        </div>
        
        <div class="user-info" id="userInfo">
            <h3><i class="fas fa-user"></i>用户信息</h3>
            <div class="user-details" id="userDetails">
                <!-- 用户信息将在这里动态显示 -->
            </div>
        </div>
        
        <div class="api-info">
            <h3><i class="fas fa-code"></i>API状态码说明</h3>
            <div class="status-codes">
                <div class="status-code"><span class="code">2000</span> 操作成功</div>
                <div class="status-code"><span class="code">3000</span> 操作失败</div>
                <div class="status-code"><span class="code">1000</span> 用户名被占用</div>
                <div class="status-code"><span class="code">1001</span> 用户名或密码错误</div>
                <div class="status-code"><span class="code">1002</span> 未登录</div>
            </div>
        </div>
    </div>

    <script>
        // 切换登录和注册表单
        document.getElementById('showRegisterBtn').addEventListener('click', function() {
            document.querySelector('.card:first-child').style.display = 'none';
            document.getElementById('registerCard').style.display = 'block';
        });
        
        document.getElementById('showLoginBtn').addEventListener('click', function() {
            document.getElementById('registerCard').style.display = 'none';
            document.querySelector('.card:first-child').style.display = 'block';
        });
        
        // 注册表单处理
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = {
                username: document.getElementById('regUsername').value,
                password: document.getElementById('regPassword').value,
                email: document.getElementById('regEmail').value,
                phone: document.getElementById('regPhone').value
            };
            
            // 模拟发送注册请求
            const messageElement = document.getElementById('registerMessage');
            messageElement.style.display = 'block';
            
            // 模拟API响应 - 这里随机返回成功或失败
            const isSuccess = Math.random() > 0.5;
            
            if (isSuccess) {
                messageElement.className = 'message success';
                messageElement.textContent = '注册成功！请返回登录页面登录。';
                
                // 清空表单
                document.getElementById('registerForm').reset();
            } else {
                messageElement.className = 'message error';
                messageElement.textContent = '注册失败，用户名已被占用。';
            }
        });
        
        // 登录表单处理
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = {
                username: document.getElementById('loginUsername').value,
                password: document.getElementById('loginPassword').value
            };
            
            // 模拟发送登录请求
            const messageElement = document.getElementById('loginMessage');
            messageElement.style.display = 'block';
            
            // 模拟API响应 - 这里随机返回成功或失败
            const isSuccess = Math.random() > 0.5;
            
            if (isSuccess) {
                // 登录成功
                messageElement.className = 'message success';
                messageElement.textContent = '登录成功！';
                
                // 显示用户信息
                const userInfo = {
                    id: Math.floor(Math.random() * 1000) + 1,
                    username: formData.username
                };
                
                displayUserInfo(userInfo);
                
                // 清空表单
                document.getElementById('loginForm').reset();
            } else {
                // 登录失败
                messageElement.className = 'message error';
                messageElement.textContent = '用户名或密码错误，请重试。';
            }
        });
        
        // 显示用户信息
        function displayUserInfo(user) {
            const userInfoElement = document.getElementById('userInfo');
            const userDetailsElement = document.getElementById('userDetails');
            
            userDetailsElement.innerHTML = `
                <div class="user-detail">
                    <div class="label">用户ID</div>
                    <div>${user.id}</div>
                </div>
                <div class="user-detail">
                    <div class="label">用户名</div>
                    <div>${user.username}</div>
                </div>
            `;
            
            userInfoElement.style.display = 'block';
        }
    </script>
</body>
</html>